
	Ext.namespace("panel.widgets.chunks.buttons");

	/**
	 * @param {Object} config
	 *
	 * config.handler Function
	**/
	panel.widgets.chunks.buttons.close = function(config) {
		
		var button = new Ext.Button({
										
			iconCls : "icon_action_ok",
			text    : "Close",
			handler : Ext.value(config.handler, undefined)
			
		});
		
		return button;
		
	};

	/**
	 * @param {Object} config
	 *
	 * config.text
	 * config.store    Ext.data.Store
	 * config.callback Function
	**/
	panel.widgets.chunks.buttons.clear_all_items = function(config) {
		
		config      = Ext.value(config, {});
		config.text = Ext.value(config.text, "Clear all");
		
		var button = new Ext.Button({
			
			cls     : "x-color-red x-btn-text-icon",
			iconCls : "icon_action_delete",
			text    : config.text,
			
			listeners: {
				
				render: function() {
					
					this.btnEl.addClass("s_bold c_red");
					
				}
				
			},
			
			handler: function() {
			
				Ext.Msg.show({
					
					title: "Confirmation",
					
					msg: [
						
						"<font class='c_red s_bold fnt_size_main'>",
						"Are you sure you want to remove all items?",
						"</font>"
						
					].join(""),
					
					width   : 400,
					buttons : Ext.Msg.YESNO,
					icon    : Ext.MessageBox.QUESTION,
					fn      : function(a) {
						
						if( a != "yes" ) {
							return; }
						
						if( config.store ) {
							config.store.removeAll(); }
						
						if( config.callback instanceof Function ) {
							config.callback(); }
						
					}
					
				});
				
			}
			
		});
		
		if( config.store ) {
			
			button.on("render", function(me) {
					
				var _fe = function() { 

					me.setDisabled( !config.store.getCount() ); 
					
				};
				
				config.store.on("load",   _fe);
				config.store.on("add",    _fe);
				config.store.on("clear",  _fe);
				config.store.on("remove", _fe);
				
			});
			
		}	// if
		
		return button;
		
	};
